package com.cloud.phone.broadcastReceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.blankj.utilcode.util.SPUtils;
import com.cloud.phone.constants.Constants;
import com.cloud.phone.task.bean.UserInfo;
import com.cloud.phone.view.TsUtils;
import com.cloud.phone.websocket.WebsocketUtil;

public class AppInstallReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Uri data=intent.getData();
        if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
            TsUtils.showTips("检测到有应用被安装，更新数据");
            WebsocketUtil.getWebsocketUtil().updatePhoneStatus();
        } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
            TsUtils.showTips("检测到有应用被卸载，更新数据");
            if(data!=null){
                String packageName = data.getSchemeSpecificPart();
                if(Constants.tiktokPackageName.equals(packageName)){
                    SPUtils.getInstance().put(UserInfo.class.getSimpleName(),"");
                }
            }
            WebsocketUtil.getWebsocketUtil().updatePhoneStatus();
        }
    }
}

